package com.atguigu.myclock;

import java.util.concurrent.locks.ReentrantLock;

public class MyReentrantLock {
//    使用synchronized实现可重入锁：
//    public synchronized void a(){
//        this.b();
//        System.out.println("a");
//    }
//    public synchronized  void  b(){
//        System.out.println("b");
//    }
//
//    public static void main(String[] args) {
//        new ReentrantLock().a();
//    }

   // 使用ReentrantLock实现可重入锁：
    private final ReentrantLock lock = new ReentrantLock();
    public void a(){
        lock.lock();
        try{
        this.b();
            System.out.println("a");
        }finally{
              lock.unlock();
         }
    }
    public void b(){
        lock.lock();
        try{
            System.out.println("b");
        }finally{
              lock.unlock();
         }
    }
    public static void main(String[] args) {
        new MyReentrantLock().a();
    }
}
